package com.designmodel.designmodel.Proxy_Pattern_代理模式.JDK代理;

import com.designmodel.designmodel.Proxy_Pattern_代理模式.静态代理.RealSubject;
import com.designmodel.designmodel.Proxy_Pattern_代理模式.静态代理.Subject;
import com.sun.org.apache.bcel.internal.generic.RETURN;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JDKProxy {
	public  Object getJDKProxy(Object o){
		//下面属性设置会在工程下生成代理类的class
		//System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");


		Object obj= (Subject) Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(), o.getClass().getInterfaces(),
				new InvocationHandler() {
					@Override
					public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

						Object returnValue = method.invoke(o, args);
						return returnValue;
					}
				});
		return  obj;
	}

		//subject.request();




}
